﻿using Marmat.Foundation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.FrameWork
{
    public sealed partial class SystemCommand
    {
        /// <summary>
        /// 重新登录命令。
        /// </summary>
        public static void ReLogin()
        {
            var reLogin = Marmat.FrameWork.SystemCommand.GetService<Marmat.Foundation.IReLogin>();
            if (reLogin is null)
                throw new NullReferenceException("没有找到 Marmat.Foundation.IReLogin 服务。");
            reLogin.Invoke();
        }

        /// <summary>
        /// 获取当前用户的用户id。
        /// </summary>
        /// <returns></returns>
        public static string GetUserID()
        {
            return GetUserProvider().UserID;
        }

        /// <summary>
        /// 获取登录用户的信息。
        /// </summary>
        /// <returns></returns>
        public static IUserProvider GetUserProvider()
        {
            return GetService<Marmat.Foundation.IUserProvider>();
        }

        /// <summary>
        /// 获取登录用户的信息。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IUserProvider GetUserProvider<T>() where T : IUserProvider
        {
            return GetService<Marmat.Foundation.IUserProvider>();
        }
    }
}
